﻿Imports Microsoft.TeamFoundation.WorkItemTracking.Client

Public Class StickyDisplayControl

    Private m_Project As Project

    Public ReadOnly Property Project() As Project
        Get
            Return m_Project
        End Get
    End Property

    Private m_Node As Node

    Public ReadOnly Property Node() As Node
        Get
            Return m_Node
        End Get
    End Property

    Public Sub SetValues(ByVal Project As Project, ByVal Node As Node)
        m_Project = Project
        m_Node = Node
        Refresh()
    End Sub

    Public Shadows Sub Refresh()
        Me.ux_FlowLayoutPanel.Controls.Clear()
        '------------------------------
        Me.Label1.Text = Node.Path

        Dim qry As New System.Text.StringBuilder
        qry.Append("SELECT [System.Id], [System.Title] ")
        qry.Append("FROM WorkItems ")
        qry.Append("WHERE ")
        qry.Append("(")
        qry.Append("[System.WorkItemType] = 'Change Request'  ")
        qry.Append("OR  [System.WorkItemType] = 'Requirement'")
        qry.Append(")  ")
        If m_Node.IsIterationNode Then
            qry.Append("AND  [System.IterationID] = '" & m_Node.Id & "' ")
        Else
            qry.Append("AND  [System.AreaID] = '" & m_Node.Id & "' ")
        End If
        qry.Append("ORDER BY [System.Id]")

        Dim qryrslt As WorkItemCollection = Project.Store.Query(qry.ToString)

        For Each wi As WorkItem In qryrslt
            Dim newSIC As New StickyItemControl
            newSIC.SetValues(Project, Node, wi)
            Me.ux_FlowLayoutPanel.Controls.Add(newSIC)
        Next
        '--------------
        MyBase.Refresh()
    End Sub

End Class
